watchAudioDevices

Calls a callback every time an audio input or output device is connected or disconnected.

function watchAudioDevices(callback: (event: AudioDeviceListChangedEvent) => void): () => void;

About

The watchAudioDevices() function listens for the devicechange event of navigator.mediaDevices, enumerates the devices again, and passes the current audio inputs and outputs to the callback. Useful to keep a device selection menu up to date.

The callback is only called on changes, not right away. Call listAudioInputDevices() and listAudioOutputDevices() once for the initial lists.

An AudioDevice also fires a devices-changed event with the same payload. Use watchAudioDevices() when you do not have (or do not want to depend on) an audio device.

You do not need this function to handle an unplugged device: AudioDevice and InputChannel fall back to the default device by themselves.

Parameters

Returns

  • () => void – A function that stops watching.

Example

import { watchAudioDevices } from "@fluex/fluexgl-dsp";

const stopWatching = watchAudioDevices(({ inputs, outputs }) => {
    renderDeviceMenu(inputs, outputs);
});

// Later:
stopWatching();

Error and warnings

No custom FluexGL-DSP error codes are currently emitted by this function.